﻿using Microsoft.AspNetCore.Mvc;
using orm.sqlsugar.api.Entities;
using SqlSugar;

namespace orm.sqlsugar.api.Controllers
{
    /// <summary>
    /// 大数据操作
    /// </summary>
    public class BulkController(ISqlSugarClient sqlSugarClient) 
        : SqlSugarBaseController(sqlSugarClient)
    {
        [HttpPost]
        public async Task<IActionResult> Insert()
        {
            var orders = new List<Order>
            {
                new()
                {
                    Number = DateTime.Now.ToString("yyyyMMddHHmmss"),
                    CreateTime = DateTime.Now
                },
                new()
                {
                    Number = DateTime.Now.ToString("yyyyMMddHHmmss"),
                    CreateTime = DateTime.Now
                }
            };

            // 1000 条以上时使用
            return Ok(await SqlSugarClient
                .Fastest<Order>()
                .BulkCopyAsync(orders) > 0);
        }
    }
}
